#!/bin/bash
# mondorestore.sh wrapper

verbose=""
output_directory="/"
SHARE_MOUNT_DIR="/mnt/share"
source emabs_common.sh

usage()
{
cat << EOF
usage: $0 -s 192.168.1.1:/share/ -f iso_file -d iso_diff_file

Automate system restoration from Mondo ISOs (both full and differential)

OPTIONS:
   -h      Show this message
   -s      NFS server address and share
   -f      Path to Full backup ISO
   -d      Path to Differential backup ISO
   -v      Verbose

Examples:
    Assuming the ISOs are in 192.168.1.1:/share/isos/ and /share is mounted in /mnt/share:
    $0 -s 192.168.1.1:/share/ -f /mnt/share/isos/gentoo-1.iso -d /mnt/share/isos/diff-1.iso
EOF
}


while getopts "hf:d:s:v" OPTION
do
     case $OPTION in
         h)
             usage
             exit
             ;;
         f)
             # path to full backup ISO
             iso_full_input_path=$OPTARG
             ;;
         s)
             # path to full backup ISO
             nfs_server=$OPTARG
             ;;
         v)
             verbose="-v"
             ;;
         d)  
             # path to differential backup ISO
             iso_diff_backup_path=$OPTARG
             ;;
         ?)
             usage
             exit
             ;;
     esac
done

if [[ -z $nfs_server ]] || [[ -z $iso_full_input_path ]] || [[ -z $iso_diff_backup_path ]]
then
    usage
    exit 1
fi

if grep -qs "$SHARE_MOUNT_DIR" /proc/mounts
then
    exec_cmd "umount $SHARE_MOUNT_DIR"
fi
exec_cmd "mount -t nfs $nfs_server $SHARE_MOUNT_DIR"

mondorestore.sh -f $iso_full_input_path $verbose -d $iso_diff_backup_path -o $output_directory 
